package com.cn.util;

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

public class SystemConfigPropertyUtil {

    private static Properties properties = new Properties();

    static {
        try {
            ResourceLoader resourceLoader = new DefaultResourceLoader();
            Resource resuorce = resourceLoader.getResource("classpath:/system.properties");
            properties.load(new FileReader(resuorce.getFile()));

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getProperty(String name) {
        Object v = properties.get(name);
        return v == null ? "" : v.toString();
    }

    public static void main(String[] args) {
        System.out.println(getProperty("listen_ip"));
    }

}
